package com.gko100.dao.impl;

import java.util.List;


import com.gko100.dao.UserPermDao;
import com.gko100.dao.basehibernatesupport.BaseHibernateDaoSupport;

import com.gko100.model.User;
import com.gko100.model.UserPerm;


public class UserPermDaoHibernate extends BaseHibernateDaoSupport implements UserPermDao {

	public void add_userPerm(UserPerm userPerm) {
		
		this.getHibernateTemplate().save(userPerm);
		
	}

	public void del_userPerm(UserPerm userPerm) {
		
		this.getHibernateTemplate().delete(userPerm);
		
	}

	public UserPerm findUserPermByUserPermId(Integer userPermId) {
		
		UserPerm userPerm = this.getHibernateTemplate().get(UserPerm.class, userPermId);
		if(userPerm!=null){
			return userPerm;
		}else{
			System.out.println(this.getClass().getName()+"---"+new Exception().getStackTrace()[0].getMethodName()+"---user======null");
			return null;
		}
		
	}

	public List<UserPerm> findUserPermList() {
		
		List<UserPerm> userPermList = this.getHibernateTemplate().find("from UserPerm");
		if(userPermList!=null&&userPermList.size()>=1){
			return userPermList;
		}else{
			
			System.out.println(this.getClass().getName()+"---"+new Exception().getStackTrace()[0].getMethodName()+"---userPermList======null");
			return null;
		}
		
	}

	public List<UserPerm> findUserPermListByUser(User user) {
		
		List<UserPerm> userPermList = this.getHibernateTemplate().find("from UserPerm as up where up.user=?", user);
		if(userPermList!=null&&userPermList.size()>=1){
			return userPermList;
		}else{
			
			System.out.println(this.getClass().getName()+"---"+new Exception().getStackTrace()[0].getMethodName()+"---userPermList======null");
			return null;
		}
		
	}

	public void modify_userPerm(UserPerm userPerm) {
		
		this.getHibernateTemplate().update(userPerm);
		
	}

	

	

}
